#ifndef _TDSCDMAAPI_H_
#define _TDSCDMAAPI_H_

#include "syscore.h"
#include "apis.h"
#include "./../gsm/network_frame.h"

#ifdef __cplusplus
extern "C" {
#endif

#define I32  S32

#define TDSCDMA_MODULE_IP       "192.168.178.111"
#define TDSCDMA_BOARD_IP        "192.168.178.205"
#define TDSCDMA_BOARD_UDP_PORT  "6060"
#define TDSCDMA_MODULE_UDP_PORT "6060"

/**
 *****************************************************************************************
 * Message Type and message code between TDSCDMA board and TDSCDMA module
 * the same for request and response
 *
 *****************************************************************************************
 */
#define MSG_INIT		                0xDC000000
#define MSG_INIT_ACK		            0xDC000001
#define MSG_INIT_CONFIGURE		        0xDC000002
#define MSG_INIT_CONFIGURE_ACK		    0xDC000003
#define MSG_REM_CELL_IND		        0xDC050004
#define MSG_REM_CELL_IND_ACK		    0xDC050005
#define MSG_CELL_STATE		            0xDC000004
#define MSG_CELL_STATE_ACK		        0xDC000005

#define MSG_DOWNLOAD_REQ		        0xDC010000
#define MSG_DOWNLOAD_ACK		        0xDC010001
#define MSG_UPLOAD_REQ		            0xDC010002
#define MSG_UPLOAD_ACK		            0xDC010003
#define MSG_TRANSFER_COMPLETE_IND		0xDC010004
#define MSG_TRANSFER_COMPLETE_ACK		0xDC010005
#define MSG_GET_VERSION		            0xDC020000
#define MSG_GET_VERSION_ACK		        0xDC020001
#define MSG_REBOOT		                0xDC020004
#define MSG_REBOOT_ACK		            0xDC020005
#define MSG_HEARTBEAT	        	    0xDC020008
#define MSG_HEARTBEAT_ACK	        	0xDC020009
#define MSG_GET_SCAN_CELL		        0xDC050000
#define MSG_GET_SCAN_CELL_ACK		    0xDC050001
#define MSG_SET_SCAN_CELL		        0xDC050002
#define MSG_SET_SCAN_CELL_ACK		    0xDC050003
#define MSG_REM_CELL_IND		        0xDC050004
#define MSG_SET_CELL		            0xDC03000A
#define MSG_SET_CELL_ACK		        0xDC03000B
#define MSG_SET_RF_SWITCH		        0xDC02000C
#define MSG_SET_RF_SWITCH_ACK		    0xDC02000D
#define MSG_SET_SYNC		            0xDC060006
#define MSG_SET_SYNC_ACK		        0xDC060007
#define MSG_ALARM_IND		            0xDC040004
#define MSG_GET_RF_SWITCH		        0xDC02000A
#define MSG_GET_RF_SWITCH_ACK		    0xDC02000B
#define MSG_GET_SYNC		            0xDC060004
#define MSG_GET_SYNC_ACK		        0xDC060005
#define MSG_UEID_RPT		            0xDC070005

#define MSG_TDSCDMA_MJVER               0x0
#define MSG_TDSCDMA_MNVER               0x1
#define MSG_TDSCDMA_RESULT_OK           0x0
#define MSG_TDSCDMA_RESULT_NOK          0x1
#define GENERAL_HEADER_LENGTH           sizeof(GeneralHeader)
typedef struct GeneralHeaderTag
{
    U32    		sessionId;   
    U8          mjVer;
    U8          mnVer;	
    U16         reserved;
    U32         messageId;
	U32 		length;
}GeneralHeader;

typedef struct MsgInitTag
{
    char  serial_number[64];
    char  product_class[64];
    char  version[64];
    U16   event;
    U16   reserve;
}MsgInit;

typedef struct MsgCellStateTag
{
    U32  state;
    U16  uarfcn;
    U16  cell_parameter_id;
}MsgCellState;

typedef struct GateWayInfoTag
{
    char femtoGW_address[64];
    U32  server_port;
    U32  local_port;
}GateWayInfo;


typedef struct CellInfoTag
{
    U16    uarfcn;
    U16    cell_parameter_id;   //PSC
    S16    fap_txPower;
    U16    lac;   
}CellInfo;

typedef struct MccInfo
{
    char       date[3];
    char       reserve;   
}MccInfo;

typedef struct MncInfo
{
    U16        n;
    U16        reserve1; 
    char       date[3];
    char       reserve;         
}MncInfo;

typedef struct PlmnIdTag
{
    MccInfo    mcc;
    MncInfo    mnc;   
}PlmnId;

typedef struct NeighbourCellTag
{
    U16             enable;
    U16             must_include;
    PlmnId          plmn_id;
    U16             rnc_id;
    U16             cid;
    U16             lac;
    U16             rac;
    U16             reserve;   
    U16             uarfcn;
    U16             cell_parameter_id;
    S16             pccpch_txPower;       
}NeighbourCell;


typedef struct NeighbourCellListTag
{
    U16                 inter_freqCell_count;
    U16                 reserve1;
    NeighbourCell       inter_freqCell[8];
    U16                 intra_freqCell_count;
    U16                 reserve2;
    NeighbourCell       intra_freqCell[8];
}NeighbourCellList;

typedef struct CoreNetworkTag
{
    PlmnId          plmn_id;    
    PlmnId          equiv_plmn_id;
    U16             sac;    
    U16             lac;
    U16             rac;
    U16             pagain;     
}CoreNetwork;

typedef struct AlarmConfigTag
{
    U16             rf_switch;    
    U16             level;    
}AlarmConfig;

typedef struct TimeInfoTag
{
    char            ntp_server1[64];
    char            ntp_server2[64];
    S8              time_zone;
}TimeInfo;

typedef struct MsgInitConfigTag
{
    GateWayInfo          gateway;
    CellInfo             cell;
    NeighbourCellList    neighbour_cell;
    CoreNetwork          cn;
    AlarmConfig          alarm;
    TimeInfo             time;
}MsgInitConfig;

typedef struct RemCellInfoTag
{
    U16             UARFCN;
    U8              PCCPCHRSCP;
    U8              RSSI;
    U8              CellParametersId;    
    PlmnId          PLMN_ID;
    U16             lac;    
    U8              rac;
    U32             CellID;    
    U16             InterCellnum;
    U16             interFreqcell[32];        
}RemCellInfo;

typedef struct MsgRemCellIndTag
{
    U8              result;
    U16             rem_cell_count;
    U8              cell0_cpi;
    U16             cell0_uarfcn;
    U16             cell0_txpower;
    U8              cell1_cpi;
    U16             cell1_uarfcn;
    U16             cell1_txpower;      
    U8              rem_cell_index; 
    U16             reserverd;        
    RemCellInfo     rem_cell;       
}MsgRemCellInd;

typedef struct MsgGetVersionAckTag
{
    char             hw_version[64];
    char             sw_version[64];
}MsgGetVersionAck;

typedef struct MsgSetCellTag
{
    U16             uarfcn;
    U16             cell_parameter_id;
    U16             fap_txPower;    
    U16             reserve;   
}MsgSetCell;

#define MsgGetScanCellACK    MsgScanCell
#define MsgGetScanCell       MsgScanCell
#define MsgSetScanCell       MsgScanCell
typedef struct MsgScanCellTag
{
    U16             scan_type;
    U16             scan_on_boot;    
    U32             scan_period;   
}MsgScanCell;

union
{
    U32             standalone;
    U32             gps;
    U32             e1588;
    
    struct          OnTheAirTag 
    {
        U16         uarfcn;
        U16         cell_parameter_id;
    }onTheAir;         
}SyncConfig;

typedef struct MsgSetSyncTag
{
    U16             sync_type;
    U16             sync_handle;
    //SyncConfig      sync;     
}MsgSetSync;

#define     ALARM_CODE_CELL_SETUP_FAILURE       0x02000003
#define     ALARM_CODE_ISCP_OVER_THRESHOLD      0x03000000
#define     ALARM_CODE_LOST_SYNC                0x03000001
#define     ALARM_CODE_OVERFLOW_THE_TEMP        0x04000000
#define     ALARM_CODE_UNDERFLOW_THE_TEMP       0x04000001

typedef struct MsgAlarmIndTag
{
    U32             alarm_id;
    U8              action;
    U8              type;     
    U16             level;
    char            time[32];
    U32             fault_code;
    char            fault_string[256];
}MsgAlarmIndTag;

typedef struct UeIdReportTag
{
    U8              imsi[16];
    U8              imei[16]; 
}UeIdReport;

typedef struct MsgUeReportTag
{
    U32             UeIDcount;
    UeIdReport      UeIdRpt[10];
}MsgUeReport;

//internal marco
#define TICK_INTERVAL                  1000
#define TICK_SECOND                    (TICK_INTERVAL / 1000)    

#define INVALID_CMD_CODE               0xffff
#define INVALID_SRC_ID                 0xffff

#define UE_ID_LENGTH                   16 
#define MSG_MAX_LENGTH                 2048

typedef enum {
    TDSCDMA_MODULE_IDLE,
    TDSCDMA_MODULE_PRECONFIG,
	TDSCDMA_MODULE_CONFIGING,
    TDSCDMA_MODULE_CONFIGED,
    TDSCDMA_MODULE_RESTART,
    TDSCDMA_MODULE_RUNNING,
    TDSCDMA_MODULE_SHUTDOWN,
    TDSCDMA_MODULE_NSYNC    
} tdscdmaModuleState_t;

typedef struct
{
    U32   paramType;
    U32   paramLength;
}tdscdmaParamCode_t;

typedef struct
{
    U32    mcc;
    U32    mnc;
	U32    lac;
    U32    arfcn;	
    U32    psc;      //
    U32    rac;
    U32    cellid;
	U32    autolac;
	U32    sac;	
	U32    txPower;
	U32    rxPower;
}tdscdmaParam_t;

typedef struct
{
    tdscdmaParam_t    param;
	MsgRemCellInd     remCellInd;
}tdscdmaGloadContext;


typedef struct
{
     U16           srcID;
     CMDHEADER     cmdHdr;
}tlvCmdRecord_t;

#ifdef __cplusplus
}
#endif

#endif
